package com.stlm2.controller.user;

import com.stlm2.core.base.BaseController;
import com.stlm2.dems.user.service.SystemPrivilegeService;
import com.stlm2.util.codecontent.CodeContent;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/8/2.
 */
@Controller
@RequestMapping("/systemPrivilegeC")
public class SystemPrivilegeController  extends BaseController {
    @Resource
    private SystemPrivilegeService systemPrivilegeService;
    /*zlq
*查找资源列表页面
* */
    @ResponseBody
    @RequestMapping(value="/list",produces="application/json;charset=UTF-8")
    public ModelAndView listView(ModelAndView modelAndView){
        modelAndView.setViewName("/resource/resource");
        return modelAndView;
    }

    /*
*查找资源列表
* zlq
*@param  token
* @param  page:页码
* @param  permissionTypeValue ：资源类型值  1：URL 2：子菜单 3:按钮 4：父菜单
* @param  superId：父类ID
* @param  isValidValue ：状态值 1:正常 0：无效
*
*/
    @ResponseBody
    @RequestMapping(value="/search.json",produces="application/json;charset=UTF-8")
    public String  search(ModelMap map,String page,String token,String permissionTypeValue,String superId,String isValidValue){
        String data=null;
        try {
            data=systemPrivilegeService.search(map,page,token,permissionTypeValue,superId,isValidValue);
        }catch (Exception e){
            e.printStackTrace();
            return CodeContent.returnFailure("搜索失败");
        }
        return  data;
    }

    /*
    *zlq
    * 根据资源类型获取父类ID列表（仅限于2:子菜单 3 ：按钮）
    * @param  permissionTypeValue ：资源类型值
     */
    @ResponseBody
    @RequestMapping(value="/getSuperIdList.json",produces="application/json;charset=UTF-8")
    public String  getSuperIdList(ModelMap map,String permissionTypeValue){
        String data=null;
        try {
            data=systemPrivilegeService.getSuperIdList(map,permissionTypeValue);
        }catch (Exception e){
            e.printStackTrace();
            return CodeContent.returnFailure("获取父类信息失败");
        }
        return  data;
    }

    	/*
	*添加系统资源
	*  @param  token
	*  @param   cnName:名称（中文简称）
	*  @param  permissionName :权限名
	*  @param  url : url
	*  @param  permissionType: 资源类型1：URL 2：子菜单 3:按钮 4：父菜单
	*  @param  permission: 初始化权限
	*  @param  superId ：父类ID
	*  @param  explain ：资源说明
	 */
        @ResponseBody
        @RequestMapping(value="/add.json",produces="application/json;charset=UTF-8")
        public String  add(ModelMap map,String token,String cnName,String  permissionName,String url,String permissionType,
                           String permission ,String superId,String explain,String number){
            String data=null;
            try {
                data=systemPrivilegeService.add(map,token,cnName,permissionName,url,permissionType,permission,superId,explain,number);
            }catch (Exception e){
                e.printStackTrace();
                return CodeContent.returnFailure("添加信息失败");
            }
            return  data;
        }

    /*
    *zlq
    *系统权限树形图
    * @param  token
    *
     */
    @ResponseBody
    @RequestMapping(value="/getPrivilegeTree.json",produces="application/json;charset=UTF-8")
    public String  getPrivilegeTree(ModelMap map ,String token){
        String data=null;
        try {
            data=systemPrivilegeService.getPrivilegeTree(map,token);
        }catch (Exception e){
            e.printStackTrace();
            return CodeContent.returnFailure("获取数据失败");
        }
        return  data;
    }
}
